/*******FIGURE A.I: EFFECTS ON LOCAL CRIME AND ARRESTS*****/

/*******RUN ANALYSIS**********/
use ../raw/crimes/homicides.dta, clear

sum homicides if tau==-1
local m = round(r(mean), .01)

eventdd homicides all, absorb(cb CBG#year pop_dec#year) timevar(tau) hdfe leads(8) lags(8) accum cluster(CBG) ci(rcap)
parmest, label saving (../estimates/figA1_homicides, replace) idstr(homicides)
outreg2 using ../output/table_crime.xls, replace stats(coef se) ctitle(`y') dec(3) addtext(mean, `m') alpha(.01, .05, .10) symbol(***, **, *) excel side

use ../raw/crimes/crimes.dta, clear

sum crime if tau==-1
local m = round(r(mean), .01)

eventdd crimes all, absorb(cb CBG#year pop_dec#year) timevar(tau) hdfe leads(6) lags(6) accum cluster(CBG) ci(rcap)
parmest, label saving (../estimates/figA1_crimes, replace) idstr(crimes)
outreg2 using ../output/table_crime.xls, append stats(coef se) ctitle(`y') dec(3) addtext(mean, `m') alpha(.01, .05, .10) symbol(***, **, *) excel side

sum arrests if tau==-1
local m = round(r(mean), .01)

eventdd arrests all, absorb(cb CBG#year pop_dec#year) timevar(tau) hdfe leads(6) lags(6) accum cluster(CBG) ci(rcap)
parmest, label saving (../estimates/figA1_arrests, replace) idstr(arrests)
outreg2 using ../output/table_crime.xls, append stats(coef se) ctitle(`y') dec(3) addtext(mean, `m') alpha(.01, .05, .10) symbol(***, **, *) excel side


/*******CREATE FIGURES**********/

local file = "figA1_homicides"
use ../estimates/`file', clear

local lower = -.15
local upper = .15
local lower1 = `lower'-.01
local upper1 = `upper'+.01
local increment = .05

local mcolor = "black"
local lcolor = "gs5"
local tsize = "large"
local labsize = "medlarge"
local titlesize = "vlarge"


gen time = real(substr(parm, -1, 1))
replace time = time*-1 if strpos(parm, "lag")==0

drop if time==.

expand 2 if time==-2, gen(omit)
replace time = -1 if omit
replace estimate = 0 if omit
replace min95 = 0 if omit
replace max95 = 0 if omit

graph twoway (scatter estimate time, mcolor(`mcolor')) (rcap min95 max95 time, lcolor(`lcolor')), ///
	xline(-.5, lcolor(red)) yline(0, lcolor(gs5)) ///
	ylabel(`lower'(`increment')`upper', grid labsize(`labsize')) yscale(range(`lower1' `upper1')) ///
	xlabel(-8(1)8, labsize(`labsize')) xscale(range(-8 8)) ///
	ytitle("Homicides", size(`tsize')) ///
	xtitle("Years to Killing", size(`tsize')) ///
	legend(off) plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
	graph export ../output/`file'.png, replace
	graph export ../output/`file'.eps, replace
	

local file = "figA1_crimes"
use ../estimates/`file', clear

local lower = -6
local upper = 6
local lower1 = `lower'-.4
local upper1 = `upper'+.4
local increment = 2

local mcolor = "black"
local lcolor = "gs5"


gen time = real(substr(parm, -1, 1))
replace time = time*-1 if strpos(parm, "lag")==0

drop if time==.

expand 2 if time==-2, gen(omit)
replace time = -1 if omit
replace estimate = 0 if omit
replace min95 = 0 if omit
replace max95 = 0 if omit

graph twoway (scatter estimate time, mcolor(`mcolor')) (rcap min95 max95 time, lcolor(`lcolor')), ///
	xline(-.5, lcolor(red)) yline(0, lcolor(gs5)) ///
	ylabel(`lower'(`increment')`upper', grid labsize(`labsize')) yscale(range(`lower1' `upper1')) ///
	xlabel(-6(1)6, labsize(`labsize')) xscale(range(-6 6)) ///
	ytitle("Crimes", size(`tsize')) ///
	xtitle("Years to Killing", size(`tsize')) ///
	legend(off) plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
	graph export ../output/`file'.png, replace
	graph export ../output/`file'.eps, replace
	
local file = "figA1_arrests"
use ../estimates/`file', clear

local lower = -15
local upper = 15
local lower1 = `lower'-1
local upper1 = `upper'+1
local increment = 5

local mcolor = "black"
local lcolor = "gs5"


gen time = real(substr(parm, -1, 1))
replace time = time*-1 if strpos(parm, "lag")==0

drop if time==.

expand 2 if time==-2, gen(omit)
replace time = -1 if omit
replace estimate = 0 if omit
replace min95 = 0 if omit
replace max95 = 0 if omit

graph twoway (scatter estimate time, mcolor(`mcolor')) (rcap min95 max95 time, lcolor(`lcolor')), ///
	xline(-.5, lcolor(red)) yline(0, lcolor(gs5)) ///
	ylabel(`lower'(`increment')`upper', grid labsize(`labsize')) yscale(range(`lower1' `upper1')) ///
	xlabel(-6(1)6, labsize(`labsize')) xscale(range(-6 6)) ///
	ytitle("Arrests", size(`tsize')) ///
	xtitle("Years to Killing", size(`tsize')) ///
	legend(off) plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
	graph export ../output/`file'.png, replace
	graph export ../output/`file'.eps, replace
	
